package com.lg.jvm;

import java.util.concurrent.TimeUnit;

public class Math {
    public static final int initData = 666;
    public static User user = new User();

    public int compute() {  //一个方法对应一块栈帧内存区域
        int a = 1;
        int b = 2;
        int c = (a + b) * 10;
        return c;
    }

    public static void main(String[] args) throws Exception {
        Math math = new Math();
        math.compute();
        //final Class<?> aClass = Class.forName("com.lg.jvm.A", false, Math.class.getClassLoader());
        final String string = A.getString();
        A.getA();
        System.out.println(string);
        TimeUnit.SECONDS.sleep(2);
        //aClass.newInstance();
    }
}

class A {
    private static A a = new A();

    static {
        System.out.println("静态代码块执行！！！");
    }

    public static String getString() {

        return "类调用静态方法是否会触发实例化?答案是并不会";
    }

    public static A getA() {
        System.out.println("这样是否会触发实例化呢？");
        // 这种情况，在类被加载的时候，静态变量就要进行赋值操作，此时的A类就会被初始化出来。并且只会初始化一次
        return a;
    }

    public A() {
        System.out.println("Class A is instance!!!");
    }
}
